/*
 * Copyright (c) 2005, 2006 CAS Dev Team
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the CAS Team nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INT_32ERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      FTSSException.hpp
 *
 * $FTS$
 */
#ifndef _FTSS_EXCEPTION_HPP__
#define _FTSS_EXCEPTION_HPP__ 1

/**
  @file FTSSException.hpp
  @brief Base exceptions set for fulltext search system
*/
#include <Types.h>

// C++ Includes
#ifdef _USE_STL_AS_BASE_EXCEPTION
#include <STLException.hpp>
#include <STLString.hpp>
#endif // _USE_STL_AS_BASE_EXCEPTION

namespace FTSS // FullTextSearchSystem
{

/**
  @class UnknownException FTSSException.hpp <FTSSException.hpp>
  @brief Base class for all CAS exceptions.
*/
class UnknownException
#ifdef _USE_STL_AS_BASE_EXCEPTION
:
  public STLW::exception
#endif // _USE_STL_AS_BASE_EXCEPTION
{
public:
	/** @return A asciz string describing the general cause of error */
	virtual CCHAR_P what() const throw() { return "Unknown Error"; }
	/** @brief A virtual destructor */
	virtual ~UnknownException() throw() { ;; }
};

/**
  @class UnixException FTSSException.hpp <FTSSException.hpp>
  @brief Unix error placeholder.
*/
class UnixException:
  public UnknownException
{
public:
	/**
	  @brief Constructor
	  @param iIErrNo - unix error code
	  @param sIReason - Error description
	*/
	inline UnixException(const INT_32 & iIErrNo, CCHAR_P sIReason) throw(): iErrNo(iIErrNo), sReason(sIReason)
	{
		;;
	}

	/** @brief return error code */
	inline INT_32 code() const throw() { return iErrNo; }

	/** @return A asciz string describing the general cause of error */
	inline CCHAR_P what() const throw() { return sReason; }

	/** A destructor */
	inline ~UnixException() throw() { ;; }
private:
	/** Unix errno        */
	const INT_32      iErrNo;
	/** Error description */
	CCHAR_P           sReason;
};

/**
  @class OverflowException FTSSException.hpp <FTSSException.hpp>
  @brief Thrown to indicate overflow errors.
*/
class OverflowException:
  public UnknownException
{
public:
	/**
	  @brief Constrcutor
	  @param iIPos - requseted position
	  @param iISize - Max. available size
	*/
	inline OverflowException(const INT_32 & iIPos, const INT_32 & iISize) throw(): iPos(iIPos), iSize(iISize) { ;; }

	/** @brief Requested position */
	inline INT_32 pos()  const throw() { return iPos; }

	/** @brief Maximum container size */
	inline INT_32 size() const throw() { return iSize; }

	/** @return A asciz string describing the general cause of error */
	inline CCHAR_P what() const throw() { return "pos >= size"; }

	/** A destructor */
	inline ~OverflowException() throw() { ;; }
private:
	/** Requested position     */
	INT_32        iPos;
	/** Maximum container size */
	INT_32        iSize;
};

/**
  @class NullPointerException FTSSException.hpp <FTSSException.hpp>
  @brief Thrown to indicate NULL pointer errors.
*/
class NullPointerException:
  public UnknownException
{
public:
	/**
	  @brief Constrcutor
	  @param sIReason - Error description
	*/
	inline NullPointerException(CCHAR_P sIReason) throw(): sReason(sIReason)
	{
		;;
	}

	/** @return A asciz string describing the general cause of error */
	inline CCHAR_P what() const throw() { return sReason; }

	/** A destructor */
	inline ~NullPointerException() throw() { ;; }
private:
	/** Error description */
	CCHAR_P        sReason;
};

/**
  @class LogicException FTSSException.hpp <FTSSException.hpp>
  @brief Logical errors, for example, problems in the INT_32ernal logic of a program.
*/
class LogicException:
  public UnknownException
{
public:
	/**
	  @brief Constrcutor
	  @param sIReason - Error description
	*/
	inline LogicException(CCHAR_P sIReason) throw(): sReason(sIReason)
	{
		;;
	}

	/**
	  @return A asciz string describing the general cause of error
	*/
	inline CCHAR_P what() const throw() { return sReason; }

	/** A destructor */
	inline ~LogicException() throw() { ;; }
private:
	/** Error description */
	CCHAR_P     sReason;
};

} // namespace FTSS
#endif // _FTSS_EXCEPTION_HPP__
// End.
